package com.gitee.wsl.common.ui.input.event

import com.gitee.wsl.common.ui.input.KEventListener
import com.gitee.wsl.common.ui.input.dragEventsListener

@RequiresOptIn
@Retention(AnnotationRetention.BINARY)
 annotation class ExperimentalKEvent

 object KPointerEvents {
     val down: KEventListener<KPointerEvent> = pointerEventsListener(type = EventType.Down)
     val move: KEventListener<KPointerEvent> = pointerEventsListener(type = EventType.Move)
     val up: KEventListener<KPointerEvent> = pointerEventsListener(type = EventType.Up)

     val enter: KEventListener<KPointerEvent> = pointerEventsListener(type = EventType.Enter)
     val leave: KEventListener<KPointerEvent> = pointerEventsListener(type = EventType.Leave)
     val cancel: KEventListener<KPointerEvent> = pointerEventsListener(type = EventType.Cancel)

     val drag: KEventListener<KDragEvent> = dragEventsListener()

    @ExperimentalKEvent
     val zoom: KEventListener<KZoomEvent> get() = zoomEventsListener()
}

/**
 * Marker interface on events.
 */
 interface KEvent


/**
 * Manage the propagation of the original platform event.
 */
 enum class EventPropagation {

    /**
     * Base event should be propagated back.
     */
    Continue,

    /**
     * Base event should not be propagated back to the platform.
     * Similar to event.stopPropagation() or event.consume()...
     */
    Stop;

     val stop: Boolean
        get() = this == Stop
}



// class KPointerClick {
//     companion object PointerClickEventListener : KEventListener<KPointerEvent>
//}
//
// class KPointerDoubleClick {
//     companion object PointerDoubleClickEventListener : KEventListener<KPointerEvent>
//}


/*
internal fun <T> VizRenderer.addEventHandle(handle: KEventHandle<T>) where T : KEvent {
    check(!handle.isAddedToRenderer)
    { "Can't add event handle which already added to Renderer" }

    handle.disposable = addNativeEventListenerFromHandle(handle)
}

internal expect fun <T> VizRenderer.addNativeEventListenerFromHandle(handle: KEventHandle<T>): Disposable where T : KEvent
*/


/**
 * Todo check the reason of VizRenderer receiver. Why not using KEventHandle.remove()
 */
/*internal fun <T> VizRenderer.removeEventHandle(handle: KEventHandle<T>) where T : KEvent {

    check(handle.isAddedToRenderer) { "Can't remove event handle which not added to Renderer. $handle" }

    handle.disposable!!.dispose()
    handle.disposable = null
}*/


